{extend name="admin/admin" /}

{block name="menu"}
<!--add模态框-->

<div style="margin-top:200px;" id='add' class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
     aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <h1 style="text-align: center; font-size:20px;color:white; ">添加权限</h1>

        <div class="form-group">
            <label for="inputEmail" class="col-sm-2 control-label"> </label>
            <div class="col-sm-10">
                <input type="email"
                       class="form-control" onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')" required
                       name="name" id="inputEmail" placeholder="权限节点名称 ">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-2 control-label">Email</label>
            <div style="margin-top:30px;" class="col-sm-10">
                <input type="email"
                       class="form-control" required onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')"
                       name="description"   placeholder="描述">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">Email</label>
            <div style="margin-top:30px;" class="col-sm-10">
                <input type="email"
                       class="form-control" required
                       name="path" id="inputEmail3" placeholder="路径">
            </div>
        </div>
        <button type="button" style="margin-top: 30px;margin-left: 400px;"
                onclick="doadd()" class="btn btn-success">提交
        </button>
    </div>
</div>
<!--end模态框-->
<h1 style="text-align: center; font-size:50px;">权限管理</h1>

<div class="table-responsive">
    <table class="table" id="table2">
        <tr>
            <th width="5%" class="active">编号</th>
            <th width="25%" class="success">权限名称</th>
            <th width="25%" class="warning">描述</th>
            <th width="25%" class="info">路径</th>
            <th width="25%" class="success">状态</th>

            <th width="10%" class="danger">
                <button data-toggle="modal" data-target="#add" class="btn btn-info">
                    添加
                </button>
            </th>
        </tr>
        {volist name="da" key="k" id="v" }
        <tr>
            <td class="active">{$v['id']}</td>
            <td class="success">{$v['name']}</td>
            <td class="warning">{$v['description']}</td>
            <td class="info">{$v['path']}</td>
            <td class="success">
                {if condition="$v['status'] eq 1"}
                启用
                {else}
                禁用
                {/if}
            </td>
            <td class="danger">

                <button onclick="dodel(this)" class="btn btn-primary">删除</button>
            </td>
        </tr>
        {/volist}
    </table>
    {$da->render()}

    <script>
        //添加权限
        function doadd() {

            var description = $("input[ name='description']").val();
            var name = $("input[ name='name']").val();
            var path = $("input[ name='path']").val();
            $.ajax({
                method: 'post',
                url: "{:url('admin/Position/addPermission')}",
                data: {
                    'description': description,
                    'name': name,
                    'path': path,
                },
                dataType: 'json',
                success: function (data) {
                    if (data == 1) {
                        alert('添加成功');
                        location.reload();
                    } else {
                        alert('输入有误,请重试');
                        location.reload();
                    }

                },
                error: function () {
                    alert('输入有误,请重试');
                    // alert('服务器繁忙,请重试');
                    location.reload();

                }
            });
        }


        //删除权限
        function dodel(b) {

            var id = $(b).parents('tr').find("td:eq(0)").text();

            $.ajax({
                method: 'post',
                url: "{:url('admin/Position/delpermission')}",
                data: {
                    'id': id,
                },
                dataType: 'json',
                success: function (data) {
                    if (data == 1) {
                        alert('删除成功');
                        location.reload();
                    } else {
                        alert('删除失败,请重试');
                        location.reload();
                    }

                },
                error: function () {
                    alert('删除失败,请重试');
                    // alert('服务器繁忙,请重试');
                    location.reload();

                }
            });
        }


    </script>
    {/block}
